package com.summer.data.dialect.gauss;

import com.summer.data.dialect.AbstractDialect;
import com.summer.data.parameter.BlobParameter;
import com.summer.data.parameter.ClobParameter;
import com.summer.data.rs.extractor.KeysExtractor;
import com.summer.data.table.BaseTable;

import java.math.BigDecimal;
import java.sql.JDBCType;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ydfqy.com
 *  高斯数据库方言
 */
public class GaussDialect extends AbstractDialect {

    // todo:
    private static final Map<Class<?>, JDBCType> JAVA_2_JDBC = new HashMap<Class<?>, JDBCType>(){{
        put(Boolean.class, JDBCType.BOOLEAN);
        put(Byte.class, JDBCType.BIT);

        put(Short.class, JDBCType.SMALLINT);
        put(Integer.class, JDBCType.INTEGER);
        put(Long.class, JDBCType.BIGINT);

        put(Float.class, JDBCType.FLOAT);
        put(Double.class, JDBCType.DOUBLE);

        put(BigDecimal.class, JDBCType.DECIMAL);

        put(String.class, JDBCType.VARCHAR);

        // 日期是最复杂的
        put(LocalDate.class, JDBCType.DATE);
        put(LocalTime.class, JDBCType.TIME_WITH_TIMEZONE);
        put(LocalDateTime.class, JDBCType.TIME);

        put(Date.class, JDBCType.DATE);
        put(java.sql.Date.class, JDBCType.DATE);

        put(Timestamp.class, JDBCType.TIMESTAMP);

        put(ClobParameter.class, JDBCType.CLOB);
        put(BlobParameter.class, JDBCType.BLOB);

    }};

    @Override
    public String getPageSql(String string, Integer offset, Integer pageSize) {
        return null;
    }

    @Override
    public Map<Class<?>, JDBCType> getJDBCTypeMap() {
        return JAVA_2_JDBC;
    }

    public String getSchemaSql() {
//        select * from dba_users;	-- 数据库里面所有用户，前提是你是有dba权限的帐号
//        select * from all_users;  -- 查看你能管理的所有用户；
//        select * from user_users; -- 查看当前用户信息
        return "select * from all_users";
    }

    public String getTableSql() {
        return "select table_name from user_tables";
    }

    public String getColumnSql(String tableName) {
        return "";
    }

    @Override
    public KeysExtractor buildKeysExtractor(BaseTable table) {
        // todo:
        return new KeysExtractor();
    }
}
